//
//  ZRMainController.swift
//  weiboDemo
//
//  Created by 张睿 on 16/7/19.
//  Copyright © 2016年 张睿. All rights reserved.
//

import UIKit

class ZRMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = ZRTabBar()
        
        tabBar.closure = {
            print("tabBar按钮被点击了")
        }
        
        // 通过kvc 设置
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(ZRHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(ZRMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZRDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZRProfileViewController(), title: "我", imageName: "tabbar_profile")
        
    }

    func addChildViewController(vc:UIViewController,title: String,imageName: String) {
        
//        let homeVC = ZRHomeViewController()
//        addChildViewController(homeVC)
        vc.title = title
        vc.tabBarItem.image = UIImage(named:imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
       addChildViewController(UINavigationController(rootViewController: vc))
    }

}
